#ifndef STATE_H
#define STATE_H

#include <X11/Xlib.h>
#include "config.h"
#include "item.h"
#include "draw.h"

// Global runtime state (singleton-like, shared across modules)
struct State
{
    Config cfg;
    Display *dpy = nullptr;
    Window root = None;
    Window win = None;
    Window parentwin = None;
    Drw *drw = nullptr;
    XIC xic = nullptr; // Input Context (for Unicode)
    Atom clip = None;  // Clipboard atom
    Atom utf8 = None;  // UTF-8 string atom
    int screen = 0;

    // UI metrics
    unsigned int bh = 0;      // Item height (pixels)
    unsigned int mh = 0;      // Menu height (pixels)
    unsigned int mw = 0;      // Menu width (pixels)
    unsigned int promptw = 0; // Prompt width (pixels)
    unsigned int inputw = 0;  // Input field width (pixels)
    int lrpad = 0;            // Left/right padding (pixels)

    // Runtime data
    std::string text;         // User input text
    size_t cursor = 0;        // Input cursor position
    Item *items = nullptr;    // All menu items (source list)
    Item *matches = nullptr;  // Filtered items (visible)
    Item *matchend = nullptr; // Last filtered item
    Item *prev = nullptr;     // Previous page of items
    Item *curr = nullptr;     // Current page of items
    Item *next = nullptr;     // Next page of items
    Item *sel = nullptr;      // Selected item
};

// Get global state (thread-safe for single-threaded X11)
State &getState();

#endif // STATE_H
